package com.qianchang.microfinance.view.hsmywallet;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianchang.microfinance.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 电脑 on 2018/1/16.
 */

public class HSRecharBalanceAdapter extends BaseAdapter{

    private Context mContext;
    private LayoutInflater inflater;
    private List<MoneyBean> listStr = new ArrayList<>();
    private int index = -1;


    public HSRecharBalanceAdapter(Context context){
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        MoneyBean moneyBean = new MoneyBean();
        moneyBean.setMoneyValue("1000");
        moneyBean.setMoneyName("1000元");
        listStr.add(moneyBean);

        MoneyBean moneyBean1 = new MoneyBean();
        moneyBean1.setMoneyValue("2000");
        moneyBean1.setMoneyName("2000元");
        listStr.add(moneyBean1);

        MoneyBean moneyBean2 = new MoneyBean();
        moneyBean2.setMoneyValue("5000");
        moneyBean2.setMoneyName("5000元");
        listStr.add(moneyBean2);

        MoneyBean moneyBean3 = new MoneyBean();
        moneyBean3.setMoneyValue("10000");
        moneyBean3.setMoneyName("10000元");
        listStr.add(moneyBean3);

    }

    public void setIndex(int index){
        this.index = index;
        notifyDataSetChanged();
    }



    @Override
    public int getCount() {
        if(listStr != null && listStr.size() > 0){
            return listStr.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return listStr.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @SuppressLint("NewApi")
    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {

        Holder holder = null;
        if(view == null){
            holder = new Holder();
            view = inflater.inflate(R.layout.item_recharbalance_layout,null);
            holder.balance = (TextView) view.findViewById(R.id.money_text_id);
            view.setTag(holder);
        }else{
            holder = (Holder) view.getTag();
        }

        if(index == position){
            view.setBackgroundResource(R.drawable.shape_blue_stroke_bg);
            holder.balance.setTextColor(mContext.getResources().getColor(R.color.white));
        }else{
            view.setBackgroundResource(R.drawable.shape_grad_stroke_bg);
            holder.balance.setTextColor(mContext.getResources().getColor(R.color.color_2c2c2c));
        }

        holder.balance.setText(listStr.get(position).getMoneyName());

        return view;
    }

    private class Holder{
        private TextView balance;

    }


    public class MoneyBean{
        private String moneyValue;
        private String moneyName;

        public String getMoneyValue() {
            return moneyValue;
        }

        public void setMoneyValue(String moneyValue) {
            this.moneyValue = moneyValue;
        }

        public String getMoneyName() {
            return moneyName;
        }

        public void setMoneyName(String moneyName) {
            this.moneyName = moneyName;
        }

        @Override
        public String toString() {
            return "MoneyBean{" +
                    "moneyValue='" + moneyValue + '\'' +
                    ", moneyName='" + moneyName + '\'' +
                    '}';
        }
    }


}
